//
//  ShippedTableViewCell.m
//  BaishidaiKnight
//
//  Created by mac book on 2019/1/28.
//  Copyright © 2019年 sy. All rights reserved.
//

#import "ShippedTableViewCell.h"

@interface ShippedTableViewCell ()
@property(nonatomic,strong) UIButton * iconBtn;
@property(nonatomic,strong) UILabel * contentLabel;
@property(nonatomic,strong) UIButton * statusBtn;
@property(nonatomic,strong) UIView * lineView;
@end


@implementation ShippedTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self createSubviews];
    }
    return self;
}

#pragma mark - createSubviews
-(void)createSubviews{
    
    [self.contentView addSubview:self.iconBtn];
    [self.contentView addSubview:self.statusBtn];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.contentView);
        make.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(1);
        
    }];
    
    [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(10);
        make.size.mas_equalTo(CGSizeMake(25, 25));
        
    }];
    
    [self.statusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.contentView);
        make.height.mas_equalTo(30);
        make.right.equalTo(self.contentView).offset(-10);
        make.width.mas_equalTo(self.contentView).multipliedBy(0.25);
        
    }];
    
    
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(self.contentView);
        make.right.equalTo(self.statusBtn.mas_left);
        make.left.equalTo(self.iconBtn.mas_right).offset(10);
        
    }];
    
    
    
}


-(void)setTaskModel:(TaskModel *)taskModel{
    
    _taskModel = taskModel;
    
    TaskModel *itemModel = taskModel.items.firstObject;

    NSString*strMoney = [NSString stringWithFormat:@"%@ \n%@",itemModel.site_name,itemModel.site_addr];
    NSMutableAttributedString* attributeStr  = [[NSMutableAttributedString alloc]initWithString:strMoney];
    
    [attributeStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.f],NSForegroundColorAttributeName:[UIColor blackColor]} range:[strMoney rangeOfString:itemModel.site_name]];
    self.contentLabel.attributedText = attributeStr;
    
    self.statusBtn.userInteractionEnabled = YES;
    [self.statusBtn setBackgroundImage:[UIImage imageNamed:@"icon_sendbtn_enter"] forState:UIControlStateNormal];
    [self.statusBtn setTitle:@"确认送达" forState:UIControlStateNormal];
    [self.iconBtn setImage:[UIImage imageNamed:@"icon-sendStatus-enter"] forState:UIControlStateNormal];
    
    
    
}


-(void)statusBtnTouch:(UIButton *)sender{
    if(self.delegate && [self.delegate respondsToSelector:@selector(ConfirmTask:)]){
        [self.delegate ConfirmTask:self.taskModel];
    }
    
}




-(UIButton *)iconBtn{
    if(!_iconBtn){
        _iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_iconBtn setImage:[UIImage imageNamed:@"icon-sendStatus-enter"] forState:UIControlStateNormal];
        
    }
    return _iconBtn;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.font = [UIFont systemFontOfSize:14.f];
        _contentLabel.numberOfLines = 0;
        _contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _contentLabel.textColor = kMyColor(113, 113, 113);
    }
    return _contentLabel;
}

-(UIButton *)statusBtn{
    if(!_statusBtn){
        _statusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_statusBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_statusBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        
        [_statusBtn setBackgroundImage:[UIImage imageNamed:@"icon_sendbtn_enter"] forState:UIControlStateNormal];
        [_statusBtn setTitle:@"确认送达" forState:UIControlStateNormal];
        
        _statusBtn.titleLabel.font = [UIFont systemFontOfSize:14.f];
        [_statusBtn addTarget:self action:@selector(statusBtnTouch:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _statusBtn;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor =  kMyColor(231, 231, 231);
    }
    return _lineView;
}




- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
